package top.yihoxu.yojcodesandbox.controller;

import org.springframework.web.bind.annotation.*;
import top.yihoxu.yojcodesandbox.JavaDockerCodeSandBoxOld;
import top.yihoxu.yojcodesandbox.JavaNativeCodeSandBoxOld;
import top.yihoxu.yojcodesandbox.model.ExecuteCodeRequest;
import top.yihoxu.yojcodesandbox.model.ExecuteCodeResponse;

import javax.annotation.Resource;

/**
 * @Author dth
 * @Date 2024/5/4 02:17
 * @PackageName:top.yihoxu.yojcodesandbox.controller
 * @ClassName: MainController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/")
public class MainController {
    @Resource
    private JavaDockerCodeSandBoxOld javaDockerCodeSandBoxOld;

    @Resource
    private JavaNativeCodeSandBoxOld javaNativeCodeSandBoxOld;

    @GetMapping("/health")
    public String healthCheck() {
        return "ok";
    }

    @PostMapping("/executeCode")
    public ExecuteCodeResponse executeCode(@RequestBody ExecuteCodeRequest executeCodeRequest) {
        if (executeCodeRequest==null){
            throw new RuntimeException("请求参数为空");
        }
        return javaDockerCodeSandBoxOld.executeCode(executeCodeRequest);

    }
}
